package com.ctsims.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctsims.common.annotation.Log;
import com.ctsims.common.core.controller.BaseController;
import com.ctsims.common.core.domain.AjaxResult;
import com.ctsims.common.enums.BusinessType;
import com.ctsims.system.domain.CtsCls;
import com.ctsims.system.service.ICtsClsService;
import com.ctsims.common.utils.poi.ExcelUtil;
import com.ctsims.common.core.page.TableDataInfo;

/**
 * 班级Controller
 *
 * @author hhz
 * @date 2023-03-30
 */
@RestController
@RequestMapping("/system/cls")
public class CtsClsController extends BaseController
{
    @Autowired
    private ICtsClsService ctsClsService;

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('system:cls:list')")
    @GetMapping("/list")
    public TableDataInfo list(CtsCls ctsCls)
    {
        startPage();
        List<CtsCls> list = ctsClsService.selectCtsClsList(ctsCls);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @PreAuthorize("@ss.hasPermi('system:cls:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtsCls ctsCls)
    {
        List<CtsCls> list = ctsClsService.selectCtsClsList(ctsCls);
        ExcelUtil<CtsCls> util = new ExcelUtil<CtsCls>(CtsCls.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cls:query')")
    @GetMapping(value = "/{clsId}")
    public AjaxResult getInfo(@PathVariable("clsId") Long clsId)
    {
        return success(ctsClsService.selectCtsClsByClsId(clsId));
    }

    /**
     * 新增班级
     */
    @PreAuthorize("@ss.hasPermi('system:cls:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtsCls ctsCls)
    {
        return toAjax(ctsClsService.insertCtsCls(ctsCls));
    }

    /**
     * 修改班级
     */
    @PreAuthorize("@ss.hasPermi('system:cls:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtsCls ctsCls)
    {
        return toAjax(ctsClsService.updateCtsCls(ctsCls));
    }

    /**
     * 删除班级
     */
    @PreAuthorize("@ss.hasPermi('system:cls:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clsIds}")
    public AjaxResult remove(@PathVariable Long[] clsIds)
    {
        return toAjax(ctsClsService.deleteCtsClsByClsIds(clsIds));
    }
}
